<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字符串</title>
    <script>
        let str = "hello world";
        //位置
        console.log(str[0])
        console.log(str.charAt(0))
        console.log(str.charCodeAt(0))

        //截取
        console.log(str.split(1, -1));
        console.log(str.substring(2));
        console.log(str.substr(1, 3));
        //增加

        //删除
        console.log(str.slice(1, -1))

        //补充
        console.log(str.padEnd(20, "1"));
        console.log(str.padStart(20, "1"));
        //大小写字母
        console.log(str.toUpperCase());
        console.log(str.toLowerCase());
        //判断
        console.log(str.startsWith("hell"))
        console.log(str.startsWith("ll", 2))
        console.log(str.endsWith("ld"))

        //去空
        console.log("   a   ".trim())
        console.log("   a   ".trimEnd())
        console.log("   a   ".trimStart())

        //替换
        while (str.indexOf("o") !== -1) {
            str = str.replace("o", "O");
        };
        //输入"background-color:red;z-index:1000;"
        //输出"backgroundColor:red;zIndex:1000;"
        let str2 = "background-color:red;z-index:1000;";
        // while (str2.indexOf("-") !== -1) {
        //     str2 = str2.replace("-c", "C");
        //     str2 = str2.replace("-i", "I")
        // }
        function trans(str) {
            while (str.indexOf("-")!==-1) {
                let pos = str.indexOf("-");
                let char = str.charAt(pos + 1);
                str=str.replace("-"+char,char.toUpperCase());
            }
            return str;
        }
        console.log(trans(str2));
        //查找字符串中出现最多的字符并输出 "asadabbasdajkjjsjjjsss"
        let str3 = "asadabbasdajkjjsjjjsssj";
        let max = 0;
        let char = '';
        let count={};
        for (let i = 0; i < str3.length; i++) {
            if(!count[str3[i]]){
                count[str3[i]]=1;
            }else{
                count[str3[i]]++;
            }
        }
        console.log(count);
        for(let i in count){
            if(max<count[i]){
                max=count[i];
                char = i;
            }
        }
        console.log(char,max);

    </script>
</head>

<body>

</body>

</html>